package algorithm.arithmetic.连续正数序列;

/**
 * @author xinchen by 2016/11/28
 * @version 1.0
 */
public class Solution {
    // 输入一个正数n，输出所有和为n连续正数序列
    public static void main(String[] args) {
        int num = Integer.parseInt(args[0]);
        StringBuilder result = new StringBuilder();
        for (int i = num / 2; i >= 2; i--) {
            int min = -1;
            if (i % 2 == 0 && (num * 2) % i == 0 && num % i != 0) {
                // 偶数
                min = ((num * 2) / i + 1) / 2 - i / 2;
            } else if (i % 2 != 0 && num % i == 0) {
                min = num / i - i / 2;
            }
            if (min > 0) {
                for (int j = 0; j < i; j++) {
                    result.append(j + min).append('+');
                }
                result.replace(result.length() - 1, result.length(), " ");
            }
        }
        System.out.println(result.toString().trim());
    }
}
